/**
 * jims.
 */
package com.jims.api.v1.controller.sys;

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.jims.master.common.beanvalidator.BeanValidators;
import com.jims.master.common.config.Global;
import com.jims.master.common.data.Message;
import com.jims.master.common.data.StringData;
import com.jims.master.common.persistence.Page;
import com.jims.master.common.utils.DateUtils;
import com.jims.master.common.utils.SecurityUtil;
import com.jims.master.common.utils.StringUtils;
import com.jims.master.common.utils.excel.ExportExcel;
import com.jims.master.common.utils.excel.ImportExcel;
import com.jims.master.common.web.BaseController;
import com.jims.master.modules.base.user.entity.MasterBaseinfo;
import com.jims.master.modules.base.user.entity.MasterContactinfo;
import com.jims.master.modules.base.user.entity.MasterDoctorinfo;
import com.jims.master.modules.base.user.service.MasterBaseinfoService;
import com.jims.master.modules.base.user.service.MasterContactinfoService;
import com.jims.master.modules.base.user.service.MasterDoctorinfoService;
import com.jims.master.modules.sys.entity.*;
import com.jims.master.modules.sys.service.*;
import com.jims.master.modules.sys.utils.UserUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.ConstraintViolationException;
import java.util.List;
import java.util.Map;

/**
 * 用户Controller
 * @author ThinkGem
 * @version 2013-8-29
 */
@Controller
@RequestMapping(value = "/user")
public class UserController extends BaseController {
	@Autowired
	private SystemService systemService;
	@Autowired
	private UserService userService;
	@Autowired
	private MasterContactinfoService masterContactinfoService;

	
	@ModelAttribute
	public User get(@RequestParam(required=false) String id) {
		if (StringUtils.isNotBlank(id)){
			return systemService.getUser(id);
		}else{
			return new User();
		}
	}
	/**
	 * @Title: findUserV100
	 * @Description: （通过电话号码查找好友）
	 * @param mobile
	 * @return java.lang.String
	 * @author WangYQ
	 * @date 2017-12-21
	 * @throws
	 */
	@RequestMapping(value = "V100/findUser",method ={RequestMethod.GET,RequestMethod.POST})
	@ResponseBody
	public User findUser(@RequestParam(required=true) String mobile){
//		Message msg=new Message();
		MasterContactinfo masterContactinfo= masterContactinfoService.findByMobliePhone(mobile);
		User user=null;
		if(masterContactinfo !=null){
			user=userService.findUserByPersonId(masterContactinfo.getBaseinfo().getId());
			String id=user.getId().substring(0,32);
			user.setId(id);
//			msg.setData(user);
		}
		return user;
	}
}
